/**
 ******************************************************************************
 * @file      AFN01.c
 * @brief     C Source file of AFN01.c.
 * @details   This file including all API functions's implement of AFN01.c.
 * @copyright
 ******************************************************************************
 */

/*-----------------------------------------------------------------------------
 Section: Includes
 ----------------------------------------------------------------------------*/
#include <stdio.h>

#include "../GDW1376_2.h"
#include "lib.h"
#include "maths.h"
#include "types.h"

/*-----------------------------------------------------------------------------
 Section: Type Definitions
 ----------------------------------------------------------------------------*/
/* NONE */

/*-----------------------------------------------------------------------------
 Section: Constant Definitions
 ----------------------------------------------------------------------------*/
/* NONE */

/*-----------------------------------------------------------------------------
 Section: Global Variables
 ----------------------------------------------------------------------------*/
/* NONE */

/*-----------------------------------------------------------------------------
 Section: Local Variables
 ----------------------------------------------------------------------------*/
/* NONE */

/*-----------------------------------------------------------------------------
 Section: Local Function Prototypes
 ----------------------------------------------------------------------------*/
/* NONE */

/*-----------------------------------------------------------------------------
 Section: Global Function Prototypes
 ----------------------------------------------------------------------------*/
/* NONE */

/*-----------------------------------------------------------------------------
 Section: Function Definitions
 ----------------------------------------------------------------------------*/
/**
 ******************************************************************************
 * @brief   输出初始化解析字符串
 * @param[in]   dir         : 传输方向:1上行(模块->集中器)" 0下行(集中器->模块)
 * @param[in]  *pin         : 输入报文
 * @param[in]   len         : 应用层报文长度
 * @param[in]  *pcb         : 回调函数
 * @param[in]  *pline_head  : 每行起始填充字符串
 * @param[in]  *pline_end   : 每行结束填充字符串
 *
 * @retval  解析错误码
 ******************************************************************************
 */
int print_AFN01(unsigned char dir, const unsigned char *pin, int len,
                pcallback pcb, const char *pline_head, const char *pline_end) {
  unsigned char DT1 = pin[0];
  unsigned char DT2 = pin[1];
  int fn = get_clear_fn(&DT1, &DT2);

  if (dir != 0) {
    pcb(pline_head);
    pcb("ERROR:初始化上行报文为确认/否认报文!");
    pcb(pline_end);
    return -ERR_AFN_FN;
  }

  CHK_APP_LEN(len, 2);

  pcb(pline_head);
  switch (fn) {
    case 1:  //硬件初始化(复位)
      pcb("硬件初始化(复位)");
      break;
    case 2:  //参数区初始化(清除所有从节点档案信息)
      pcb("参数区初始化(清除所有从节点档案信息)");
      break;
    case 3:  //数据区初始化(清除所有从节点通信信息)
      pcb("数据区初始化(清除所有从节点通信信息)");
      break;
    default:
      pcb("ERROR:不支持的FN!");
      pcb(pline_end);
      return -ERR_AFN_FN;
  }

  pcb(pline_end);

  return ERR_NONE;
}

/*--------------------------------AFN01.c------------------------------------*/
